package com.chunayev.numerology.util;

/**
 * @author Sergey Chunayev
 */
public class NameResolver {
    
    public static int calculateCharPosition(final char c) {
        final Integer value = Constants.CHAR_TO_INDEX_RU.get(c);
        if (value == null) {
            return 0;
        }
        return value;
    }
    
    public static int calculateSumm(final String name) {
        final char[] chars = name.toLowerCase().toCharArray();
        int wordSumm = 0;
        for (final Character c : chars) {
            final int value = calculateCharPosition(c);
            wordSumm += value;
        }
        return wordSumm;
    }
    
    public static int determinePosition(final int number) {
        if (number <= 49) {
            return number;
        }
        
        final int mod = number % 49;
        
        if (mod == 0) {
            return 49;
        }
        
        return mod;
    }
    
    public static int determinePosition(final String name) {
        return determinePosition(calculateSumm(name));
    }
}
